package fresher.utility;

import hapax.Template;
import hapax.TemplateException;
import hapax.TemplateLoader;
import hapax.TemplateResourceLoader;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author namlq2
 */
public class TemplateManager {

    private static TemplateManager instance = null;
    Map<String, Template> templateList;
    private TemplateLoader templateLoader;

    private TemplateManager() {
        templateList = new HashMap<String, Template>();
        templateLoader = TemplateResourceLoader.create("fresher/");
    }

    public static TemplateManager getInstance() {
        if (instance == null) {
            instance = new TemplateManager();
        }
        return instance;
    }

    public Template getTemplate(String path) throws TemplateException {
        if (templateList.containsKey(path)) {
            return templateList.get(path);
        } else {
            Template template = templateLoader.getTemplate(path);
            templateList.put(path, template);
            return template;
        }
    }
}
